package com.taiji.webfluxcurd.domain;

import com.taiji.webfluxcurd.base.IBaseRepository;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.r2dbc.repository.Modifying;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

@Repository
public interface UserRepository extends IBaseRepository<User,String> {


    @Modifying
    @Query("insert into user (id,name,age,content,created_date,modified_date) values (:#{#user.id},:#{#user.name},:#{#user.age},:#{#user.content},:#{#user.createdDate},:#{#user.modifiedDate})")
    Mono<User> addUser( User user);

    Flux<User> findAllByNameAndAgeIsNotNull(String name,Pageable pageable);

//    @Query("select * from user limit 0,3")
    @Query("select u from User u")
    Flux<User> findAllUser(Pageable pageable);
}
